package org.edu.modules.sxjy.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.edu.common.api.vo.Result;
import org.edu.modules.sxjy.entity.VeApply;
import org.edu.modules.sxjy.entity.VeBaseStudent;
import org.edu.modules.sxjy.entity.VeChange;
import org.edu.modules.sxjy.entity.VeClassTeacher;
import org.edu.modules.sxjy.entity.VeCommon;
import org.edu.modules.sxjy.entity.VeCompany;
import org.edu.modules.sxjy.entity.VeCompanyUser;
import org.edu.modules.sxjy.entity.VeDynamic;
import org.edu.modules.sxjy.entity.VePost;
import org.edu.modules.sxjy.entity.VePractice;
import org.edu.modules.sxjy.entity.VeStudent;
import org.edu.modules.sxjy.entity.VeStudentInfo;
import org.edu.modules.sxjy.feign.VeCommonClient;
import org.edu.modules.sxjy.mapper.VeChangeMapper;
import org.edu.modules.sxjy.service.IVeApplyService;
import org.edu.modules.sxjy.service.IVeChangeService;
import org.edu.modules.sxjy.service.IVeClassTeacharService;
import org.edu.modules.sxjy.service.IVeCompanyService;
import org.edu.modules.sxjy.service.IVeCompanyUserService;
import org.edu.modules.sxjy.service.IVeDynamicService;
import org.edu.modules.sxjy.service.IVePostService;
import org.edu.modules.sxjy.service.IVePracticeService;
import org.edu.modules.sxjy.service.IVeStudentService;
import org.edu.modules.sxjy.utils.DateUtils;
import org.edu.modules.sxjy.vo.VeChangeAssess;
import org.edu.modules.sxjy.vo.VeChangeInfoVo;
import org.edu.modules.sxjy.vo.VeChangeSubmitVo;
import org.edu.modules.sxjy.vo.VeChangeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VeChangeServiceImpl
        extends ServiceImpl<VeChangeMapper, VeChange>
        implements IVeChangeService
{
    @Autowired
    VeChangeMapper veChangeMapper;
    @Autowired
    IVeChangeService veChangeService;
    @Autowired
    IVeApplyService veApplyService;
    @Autowired
    IVeStudentService veStudentService;
    @Autowired
    IVePracticeService vePracticeService;
    @Autowired
    IVePostService vePostService;
    @Autowired
    IVeCompanyService veCompanyService;
    @Autowired
    IVeDynamicService veDynamicService;
    @Autowired
    private VeCommonClient veCommonClient;
    @Autowired
    private IVeClassTeacharService veClassTeacharService;
    @Autowired
    private IVeCompanyUserService veCompanyUserService;

    public List<VeChangeVo> selectAll(VeChangeVo veChangeVo, Integer startLine, Integer pageSize, VeCommon veCommon)
    {
        List<VeChangeVo> veChangeVoList = new ArrayList();
        VeCompanyUser veCompanyUser;
        if (veCommon.getUserType().contains("0"))
        {
            veChangeVoList = this.veChangeMapper.selectAll(veChangeVo, startLine, pageSize, veCommon);
        }
        else if (veCommon.getUserType().equals("1"))
        {
            List<Integer> stuBjIdList = new ArrayList();

            List<VeClassTeacher> veClassTeacherList = this.veClassTeacharService.getBanjiIdByTeacherUserId(veCommon.getUserId());
            for (VeClassTeacher veClassTeacher : veClassTeacherList) {
                if ((veClassTeacher != null) && (!"".equals(veClassTeacher))) {
                    stuBjIdList.add(Integer.valueOf(veClassTeacher.getBjId()));
                }
            }
            veCommon.setStuBjId(stuBjIdList);
            if ((stuBjIdList != null) && (stuBjIdList.size() > 0)) {
                veChangeVoList = this.veChangeMapper.selectAll(veChangeVo, startLine, pageSize, veCommon);
            } else {
                veChangeVoList = new ArrayList();
            }
        }
        else if (veCommon.getUserType().equals("2"))
        {
            Object stuResult = this.veCommonClient.queryStudentById("09d5e1e7f9b049008eee645c783a1d67", veCommon.getUserId()).getResult();
            Map stuMap = (Map)stuResult;
            if (stuMap != null)
            {
                veCommon.setStuId(Integer.parseInt(stuMap.get("id").toString()));
                veChangeVoList = this.veChangeMapper.selectAll(veChangeVo, startLine, pageSize, veCommon);
            }
        }
        else if ((veCommon.getUserType().equals("4")) || (veCommon.getUserType().equals("3")))
        {
            veCompanyUser = this.veCompanyUserService.getCpInfoByUserId(veCommon.getUserId());
            veCommon.setCpId(veCompanyUser.getCpId());

            veChangeVoList = this.veChangeMapper.selectAll(veChangeVo, startLine, pageSize, veCommon);
        }
        if ((veChangeVoList != null) && (veChangeVoList.size() > 0)) {
            for (VeChangeVo changeVo : veChangeVoList)
            {
                if (changeVo.getChangeStatus() == 0) {
                    changeVo.setChangeStatuss("待审核");
                } else if (changeVo.getChangeStatus() == 1) {
                    changeVo.setChangeStatuss("审核通过");
                } else if (changeVo.getChangeStatus() == 2) {
                    changeVo.setChangeStatuss("未通过");
                } else if (changeVo.getChangeStatus() == -1) {
                    changeVo.setChangeStatuss("已关闭");
                } else {
                    changeVo.setChangeStatuss("已关闭");
                }
                changeVo.setChangeTime(DateUtils.getDateToString(Long.parseLong(changeVo.getChangeTime())));
            }
        }
        return veChangeVoList;
    }

    public int getSumPage(VeChangeVo veChangeVo, VeCommon veCommon)
    {
        int pageNum = 0;
        if (veCommon.getUserType().contains("0"))
        {
            pageNum = this.veChangeMapper.getSumPage(veChangeVo, veCommon);
        }
        else if (veCommon.getUserType().equals("1"))
        {
            List<Integer> stuBjIdList = new ArrayList();

            List<VeClassTeacher> veClassTeacherList = this.veClassTeacharService.getBanjiIdByTeacherUserId(veCommon.getUserId());
            for (VeClassTeacher veClassTeacher : veClassTeacherList) {
                if ((veClassTeacher != null) && (!"".equals(veClassTeacher))) {
                    stuBjIdList.add(Integer.valueOf(veClassTeacher.getBjId()));
                }
            }
            veCommon.setStuBjId(stuBjIdList);
            if ((stuBjIdList != null) && (stuBjIdList.size() > 0)) {
                pageNum = this.veChangeMapper.getSumPage(veChangeVo, veCommon);
            } else {
                pageNum = 0;
            }
        }
        else if (veCommon.getUserType().equals("2"))
        {
            Object stuResult = this.veCommonClient.queryStudentById("09d5e1e7f9b049008eee645c783a1d67", veCommon.getUserId()).getResult();
            Map stuMap = (Map)stuResult;
            if (stuMap != null)
            {
                veCommon.setStuId(Integer.parseInt(stuMap.get("id").toString()));
                pageNum = this.veChangeMapper.getSumPage(veChangeVo, veCommon);
            }
        }
        else if ((veCommon.getUserType().equals("4")) || (veCommon.getUserType().equals("3")))
        {
            VeCompanyUser veCompanyUser = this.veCompanyUserService.getCpInfoByUserId(veCommon.getUserId());
            veCommon.setCpId(veCompanyUser.getCpId());

            pageNum = this.veChangeMapper.getSumPage(veChangeVo, veCommon);
        }
        return pageNum;
    }

    public VeChangeInfoVo getOneInfo(int id)
    {
        VeChange veChange = (VeChange)this.veChangeService.getById(Integer.valueOf(id));

        VeChangeInfoVo veChangeInfoVo = new VeChangeInfoVo();
        if ((veChange == null) || ("".equals(veChange))) {
            return veChangeInfoVo;
        }
        Object stuInfoResult = this.veCommonClient.getStudentInfoById("09d5e1e7f9b049008eee645c783a1d67", veChange.getStuUserId()).getResult();
        Map stuInfoMap = (Map)stuInfoResult;
        String s = JSON.toJSONString(stuInfoMap);
        VeStudentInfo veStuInfo = (VeStudentInfo)JSON.parseObject(s, VeStudentInfo.class);
        if ((veStuInfo != null) && (!"".equals(veStuInfo)))
        {
            veChangeInfoVo.setXslxdh(veStuInfo.getXslxdh());

            veChangeInfoVo.setJstxh(veStuInfo.getJstxh());

            veChangeInfoVo.setJtdz(veStuInfo.getJtdz());

            veChangeInfoVo.setJtlxdh(veStuInfo.getJtlxdh());
        }
        String specName = this.veChangeMapper.getSpecName(veChange.getSpecId());
        if ((specName != null) && (!"".equals(specName))) {
            veChangeInfoVo.setSpec(specName);
        }
        String bjName = this.veChangeMapper.getBjName(veChange.getBjId());
        if ((bjName != null) && (!"".equals(bjName))) {
            veChangeInfoVo.setBj(bjName);
        }
        veChangeInfoVo.setOldCpId(veChange.getOldCpId());
        String oldCpName = this.veChangeMapper.getCpNameByCpId(veChange.getOldCpId());
        if ((oldCpName != null) && (!"".equals(oldCpName))) {
            veChangeInfoVo.setOldCpName(oldCpName);
        }
        veChangeInfoVo.setOldPostId(veChange.getOldPostId());
        String oldPostName = this.veChangeMapper.getPostNameByPostId(veChange.getOldPostId());
        if ((oldPostName != null) && (!"".equals(oldPostName))) {
            veChangeInfoVo.setOldPostName(oldPostName);
        }
        veChangeInfoVo.setCpId(veChange.getCpId());
        String cpName = this.veChangeMapper.getCpNameByCpId(veChange.getCpId());
        if ((cpName != null) && (!"".equals(cpName))) {
            veChangeInfoVo.setCpName(cpName);
        }
        veChangeInfoVo.setPostId(veChange.getPostId());
        String postName = this.veChangeMapper.getPostNameByPostId(veChange.getPostId());
        if ((postName != null) && (!"".equals(postName))) {
            veChangeInfoVo.setPostName(postName);
        }
        String linKman = this.veChangeMapper.getLinKman(veChange.getCpId());
        if ((linKman != null) && (!"".equals(linKman))) {
            veChangeInfoVo.setLinkman(linKman);
        }
        String tel = this.veChangeMapper.getTel(veChange.getCpId());
        if ((tel != null) && (!"".equals(tel))) {
            veChangeInfoVo.setTel(tel);
        }
        VeApply veApply = (VeApply)this.veApplyService.getById(Integer.valueOf(veChange.getNewApplyId()));




        List<VeCompanyUser> veCompanyUserList = this.veChangeMapper.getCteacherUser(veChange.getCpId(), veChange.getPostId());
        if ((veCompanyUserList != null) && (veCompanyUserList.size() > 0)) {
            veChangeInfoVo.setCteacherUser(((VeCompanyUser)veCompanyUserList.get(0)).getRealName());
        }
        if (veChange.getBjId() != 0)
        {
            List<String> teacherNameList = this.veChangeMapper.getTeacherNameByBjId(veChange.getBjId());
            if ((teacherNameList != null) && (teacherNameList.size() > 0)) {
                veChangeInfoVo.setXxzdjs(teacherNameList.toString().replace("[", "").replace("]", ""));
            }
        }
        if ((veApply != null) && (!"".equals(veApply)))
        {
            veChangeInfoVo.setStartTime(DateUtils.getDateToString(veApply.getStartTime()));

            veChangeInfoVo.setEndTime(DateUtils.getDateToString(veApply.getEndTime()));

            veChangeInfoVo.setAddress(veApply.getAddress());
        }
        veChangeInfoVo.setChangeTime(DateUtils.getDateToString(veChange.getChangeTime()));
        if (veChange.getChangeStatus() == 0) {
            veChangeInfoVo.setChangeStatus("待审核");
        } else if (veChange.getChangeStatus() == 1) {
            veChangeInfoVo.setChangeStatus("审核通过");
        } else if (veChange.getChangeStatus() == 2) {
            veChangeInfoVo.setChangeStatus("未通过");
        } else if (veChange.getChangeStatus() == -1) {
            veChangeInfoVo.setChangeStatus("已关闭");
        } else {
            veChangeInfoVo.setChangeStatus("已关闭");
        }
        veChangeInfoVo.setRemark(veChange.getRemark());

        return veChangeInfoVo;
    }

    public VeChangeAssess selectAssess(int id)
    {
        VeChange veChange = (VeChange)this.veChangeService.getById(Integer.valueOf(id));


        VeStudent veStudent = (VeStudent)this.veStudentService.getById(Integer.valueOf(veChange.getStuUserId()));

        return null;
    }

    public Result<?> saves(VeChangeSubmitVo veChangeSubmitVo)
    {
        Object stuResult = this.veCommonClient.queryStudentById("09d5e1e7f9b049008eee645c783a1d67", veChangeSubmitVo.getUserId()).getResult();
        Map stuMap = (Map)stuResult;
        String s = JSON.toJSONString(stuMap);
        VeStudent veStudent = (VeStudent)JSON.parseObject(s, VeStudent.class);


        VeChange veChange = new VeChange();


        VeApply veApply = new VeApply();
        VePractice vePractice = new VePractice();
        if ((veStudent != null) && (!"".equals(veStudent)))
        {
            veApply = this.veApplyService.getByIds(veStudent.getId());

            vePractice = this.vePracticeService.getByIds(veStudent.getId());
        }
        veChange.setOldCpId(veChangeSubmitVo.getOldCpId());

        veChange.setOldPostId(veChangeSubmitVo.getOldPostId());

        veChange.setCpId(veChangeSubmitVo.getCpId());

        veChange.setPostId(veChangeSubmitVo.getPostId());
        if ((veChangeSubmitVo.getStartTime() != null) && (!"".equals(veChangeSubmitVo.getStartTime()))) {
            veApply.setStartTime(DateUtils.getStringToDate(veChangeSubmitVo.getStartTime()));
        }
        if ((veChangeSubmitVo.getEndTime() != null) && (!"".equals(veChangeSubmitVo.getEndTime()))) {
            veApply.setEndTime(DateUtils.getStringToDate(veChangeSubmitVo.getEndTime()));
        }
        veApply.setAddress(veChangeSubmitVo.getAddress());



        veChange.setOldApplyId(veApply.getId());
        if ((vePractice != null) && (!"".equals(vePractice))) {
            veChange.setOldPrcId(vePractice.getId());
        }
        veChange.setRemark(veChangeSubmitVo.getRemark());

        veChange.setChangeStatus(0);
        if ((veStudent != null) && (!"".equals(veStudent)))
        {
            veChange.setSpecId(veStudent.getSpecId());


            veChange.setChangeTime(System.currentTimeMillis());

            veChange.setStuUserId(veStudent.getId());


            veChange.setFalId(veStudent.getFalId());

            veChange.setGradeId(veStudent.getGradeId());

            veChange.setBjId(veStudent.getBjId());

            veChange.setTerminalId(1);

            veChange.setXm(veStudent.getXm());

            veChange.setXh(veStudent.getXh());

            veChange.setSfzh(veStudent.getSfzh());
        }
        VeApply veApplyNew = veApply;

        veApplyNew.setUpdateTime(System.currentTimeMillis());

        veApplyNew.setStatus(0);

        String cpName = ((VeCompany)this.veCompanyService.getById(Integer.valueOf(veChangeSubmitVo.getCpId()))).getName();
        if ((cpName != null) && (!"".equals(cpName))) {
            veApplyNew.setCpName(cpName);
        }
        veApplyNew.setCpId(veChangeSubmitVo.getCpId());
        String postName = ((VePost)this.vePostService.getById(Integer.valueOf(veChangeSubmitVo.getPostId()))).getPostName();
        if ((postName != null) && (!"".equals(postName))) {
            veApplyNew.setPostName(postName);
        }
        veApplyNew.setPostId(veChangeSubmitVo.getPostId());

        veApplyNew.setIsChange(1);
        this.veApplyService.save(veApplyNew);
        VeApply veApplyNews = new VeApply();
        if ((veStudent != null) && (!"".equals(veStudent))) {
            veApplyNews = this.veChangeMapper.getApplyNewIdByIdStuId(veStudent.getId(), veApplyNew.getCpId(), veApplyNew.getPostId());
        }
        this.veApplyService.updateById(veApply);


        veChange.setNewApplyId(veApplyNews.getId());

        this.veChangeService.save(veChange);

        return Result.OK("添加成功");
    }

    public VeChangeSubmitVo editEcho(int id)
    {
        VeChange veChange = (VeChange)this.veChangeService.getById(Integer.valueOf(id));

        VeChangeSubmitVo veChangeSubmitVo = new VeChangeSubmitVo();


        veChangeSubmitVo.setOldCpId(veChange.getOldCpId());
        String oldCpName = ((VeCompany)this.veCompanyService.getById(Integer.valueOf(veChange.getOldCpId()))).getName();
        if ((oldCpName != null) && (!"".equals(oldCpName))) {
            veChangeSubmitVo.setOldCpName(oldCpName);
        }
        veChangeSubmitVo.setOldPostId(veChange.getOldPostId());
        String oldPostName = ((VePost)this.vePostService.getById(Integer.valueOf(veChange.getOldPostId()))).getPostName();
        if ((oldPostName != null) && (!"".equals(oldPostName))) {
            veChangeSubmitVo.setOldPostName(oldPostName);
        }
        veChangeSubmitVo.setCpId(veChange.getCpId());
        String cpName = ((VeCompany)this.veCompanyService.getById(Integer.valueOf(veChange.getCpId()))).getName();
        if ((cpName != null) && (!"".equals(cpName))) {
            veChangeSubmitVo.setCpName(cpName);
        }
        veChangeSubmitVo.setPostId(veChange.getPostId());
        String postName = ((VePost)this.vePostService.getById(Integer.valueOf(veChange.getPostId()))).getPostName();
        if ((postName != null) && (!"".equals(postName))) {
            veChangeSubmitVo.setPostName(postName);
        }
        List<VeApply> veApplyList = this.veApplyService.list();
        for (VeApply veApply : veApplyList) {
            if ((veApply != null) && (!"".equals(veApply)) &&
                    (veApply.getStuUserId() == veChange.getStuUserId()) && (veApply.getStatus() == 0))
            {
                veChangeSubmitVo.setStartTime(DateUtils.getDateToString(veApply.getStartTime()));

                veChangeSubmitVo.setEndTime(DateUtils.getDateToString(veApply.getEndTime()));

                veChangeSubmitVo.setAddress(veApply.getAddress());
            }
        }
        veChangeSubmitVo.setRemark(veChange.getRemark());
        return veChangeSubmitVo;
    }

    public Result<?> edit(VeChangeSubmitVo veChangeSubmitVo)
    {
        VeChange veChange = (VeChange)this.veChangeService.getById(Integer.valueOf(veChangeSubmitVo.getId()));


        veChange.setOldCpId(veChangeSubmitVo.getOldCpId());

        veChange.setOldPostId(veChangeSubmitVo.getOldPostId());

        veChange.setCpId(veChangeSubmitVo.getCpId());

        veChange.setPostId(veChangeSubmitVo.getPostId());


        veChange.setRemark(veChangeSubmitVo.getRemark());


        VeApply veApplyNew = (VeApply)this.veApplyService.getById(Integer.valueOf(veChange.getNewApplyId()));
        if ((veApplyNew != null) && (!"".equals(veApplyNew)))
        {
            veApplyNew.setCpName(veChangeSubmitVo.getCpName());
            veApplyNew.setCpId(veChangeSubmitVo.getCpId());
            veApplyNew.setPostName(veChangeSubmitVo.getPostName());
            veApplyNew.setPostId(veChangeSubmitVo.getPostId());


            veApplyNew.setAddress(veChangeSubmitVo.getAddress());
            if ((veChangeSubmitVo.getStartTime() != null) && (!"".equals(veChangeSubmitVo.getStartTime()))) {
                veApplyNew.setStartTime(DateUtils.getStringToDate(veChangeSubmitVo.getStartTime()));
            } else {
                return Result.error("开始时间不能为空");
            }
            if ((veChangeSubmitVo.getEndTime() != null) && (!"".equals(veChangeSubmitVo.getEndTime()))) {
                veApplyNew.setEndTime(DateUtils.getStringToDate(veChangeSubmitVo.getEndTime()));
            } else {
                return Result.error("结束时间不能为空");
            }
            this.veApplyService.updateById(veApplyNew);
        }
        this.veChangeService.updateById(veChange);
        return Result.OK("修改成功");
    }

    public void updatePass(List<VeChange> veChangeList)
    {
        for (VeChange veChange : veChangeList)
        {
            VeChange veChanges = (VeChange)this.veChangeService.getById(Integer.valueOf(veChange.getId()));
            VeDynamic veDynamic = new VeDynamic();

            veChanges.setChangeStatus(1);
            this.veChangeService.updateById(veChanges);




            veDynamic.setStuUserId(veChanges.getStuUserId());

            veDynamic.setCreateTime(System.currentTimeMillis());

            veDynamic.setCreateUserId(1);

            veDynamic.setPrcId(veChanges.getOldPrcId());

            veDynamic.setPostId(veChanges.getPostId());

            String postName = ((VePost)this.vePostService.getById(Integer.valueOf(veChanges.getPostId()))).getPostName();
            if ((postName != null) && (!"".equals(postName))) {
                veDynamic.setPostName(postName);
            }
            veDynamic.setCpId(veChanges.getCpId());

            String cpName = ((VeCompany)this.veCompanyService.getById(Integer.valueOf(veChanges.getCpId()))).getName();
            if ((cpName != null) && (!"".equals(cpName))) {
                veDynamic.setCpName(cpName);
            }
            veDynamic.setRemark("在岗");

            veDynamic.setTerminalId(1);

            this.veDynamicService.save(veDynamic);





            VeChange veChangeEntity = this.veChangeMapper.getChangeByStuUserId(veChanges.getStuUserId());

            VePractice vePractice = this.veChangeMapper.getPracticeByStuUserId(veChanges.getStuUserId());
            if ((vePractice != null) && (!"".equals(vePractice)))
            {
                vePractice.setCpId(veChangeEntity.getCpId());

                String newCpName = ((VeCompany)this.veCompanyService.getById(Integer.valueOf(veChangeEntity.getCpId()))).getName();
                if ((newCpName != null) && (!"".equals(newCpName))) {
                    vePractice.setCpName(newCpName);
                }
                vePractice.setPostId(veChangeEntity.getPostId());

                String newPostName = ((VePost)this.vePostService.getById(Integer.valueOf(veChangeEntity.getPostId()))).getPostName();
                if ((newPostName != null) && (!"".equals(newPostName))) {
                    vePractice.setPostName(newPostName);
                }
                VeApply veApply = (VeApply)this.veApplyService.getById(Integer.valueOf(veChangeEntity.getNewApplyId()));
                if ((veApply != null) && (!"".equals(veApply)))
                {
                    String cteacherUserId = this.veChangeMapper.getCpUserIdByUserId(veApply.getCteacherUserId());
                    if ((cteacherUserId != null) && (!"".equals(cteacherUserId))) {
                        vePractice.setCteacherUserId(cteacherUserId);
                    }
                }
                vePractice.setStartTime(veApply.getStartTime());

                vePractice.setEndTime(veApply.getEndTime());

                vePractice.setPayment(0);

                vePractice.setAddress(veApply.getAddress());

                vePractice.setIsPro(1);

                vePractice.setTask("");


                vePractice.setUpdateTime(veChangeEntity.getChangeTime());

                vePractice.setStatus(2);

                this.vePracticeService.updateById(vePractice);
            }
            this.veChangeMapper.setNewApplyStatus(veChanges.getNewApplyId(), veChanges.getStuUserId());


            this.veChangeMapper.setOldApplyStatus(veChanges.getOldApplyId(), veChanges.getStuUserId());
        }
    }

    public void updateNoPass(List<VeChange> veChangeList)
    {
        for (VeChange veChange : veChangeList)
        {
            VeChange veChanges = (VeChange)this.veChangeService.getById(Integer.valueOf(veChange.getId()));

            veChanges.setChangeStatus(2);
            this.veChangeService.updateById(veChanges);






            VeApply oldVeApply = (VeApply)this.veApplyService.getById(Integer.valueOf(veChanges.getOldApplyId()));
            if ((oldVeApply != null) && (!"".equals(oldVeApply)))
            {
                oldVeApply.setStatus(1);
                this.veApplyService.updateById(oldVeApply);
            }
            VeApply newVeApply = (VeApply)this.veApplyService.getById(Integer.valueOf(veChanges.getNewApplyId()));
            if ((newVeApply != null) && (!"".equals(newVeApply)))
            {
                newVeApply.setStatus(2);
                this.veApplyService.updateById(newVeApply);
            }
        }
    }

    public Result<?> getStuOldCpAndPost(String userId)
    {
        Result<?> result = this.veCommonClient.queryStudentById("09d5e1e7f9b049008eee645c783a1d67", userId);
        Object stuResult = result.getResult();
        Map stuMap = (Map)stuResult;
        if (stuMap != null)
        {
            VeApply veApply = this.veChangeMapper.getStuOldCpAndPost(Integer.parseInt(stuMap.get("id").toString()));

            return Result.OK(veApply);
        }
        return Result.OK();
    }

    public Result<?> stuIsStatusChange(String userType, String userId)
    {
        if (userType.equals("2"))
        {
            Result<?> result = this.veCommonClient.queryStudentById("09d5e1e7f9b049008eee645c783a1d67", userId);
            Object stuResult = result.getResult();
            Map stuMap = (Map)stuResult;
            if ((stuMap != null) && (!"".equals(stuMap)))
            {
                String s = JSON.toJSONString(stuMap);
                VeBaseStudent veBaseStudent = (VeBaseStudent)JSON.parseObject(s, VeBaseStudent.class);
                if ((veBaseStudent != null) && (!"".equals(veBaseStudent)))
                {
                    List<VeChange> veChangeList = this.veChangeMapper.getStuIsStatusChange(veBaseStudent.getId());
                    if ((veChangeList == null) || (veChangeList.size() == 0))
                    {
                        List<VeApply> veApplyList = this.veChangeMapper.getStuApplyByStuId(veBaseStudent.getId());
                        if ((veApplyList != null) && (veApplyList.size() > 0)) {
                            return Result.OK(Boolean.valueOf(true));
                        }
                        return Result.OK(Boolean.valueOf(false));
                    }
                    return Result.OK(Boolean.valueOf(false));
                }
            }
        }
        return Result.OK();
    }

    public Result<?> deleteById(String id)
    {
        VeChange veChange = (VeChange)this.veChangeService.getById(id);

        VeApply oldVeApply = (VeApply)this.veApplyService.getById(Integer.valueOf(veChange.getOldApplyId()));
        oldVeApply.setStatus(1);
        this.veApplyService.updateById(oldVeApply);


        this.veApplyService.removeById(Integer.valueOf(veChange.getNewApplyId()));



        VePractice vePractice = this.veChangeMapper.getStuPrcInfoByStuId(veChange.getStuUserId());
        if ((vePractice != null) && (!"".equals(vePractice)))
        {
            vePractice.setCpId(oldVeApply.getCpId());
            vePractice.setCpName(oldVeApply.getCpName());

            vePractice.setPostId(oldVeApply.getPostId());
            vePractice.setPostName(oldVeApply.getPostName());

            String cteacherUserId = this.veChangeMapper.getCteacherUserByCpUserId(oldVeApply.getCteacherUserId());
            if ((cteacherUserId != null) && (!"".equals(cteacherUserId))) {
                vePractice.setCteacherUserId(cteacherUserId);
            }
            vePractice.setStartTime(oldVeApply.getStartTime());

            vePractice.setEndTime(oldVeApply.getEndTime());

            vePractice.setAddress(oldVeApply.getAddress());






            vePractice.setStatus(1);
            this.vePracticeService.updateById(vePractice);
        }
        this.veChangeService.removeById(id);
        return Result.OK("删除成功");
    }

    public Result<?> stuDisperseIsChange(String userType, String userId)
    {
        if (userType.equals("2"))
        {
            Result<?> result = this.veCommonClient.queryStudentById("09d5e1e7f9b049008eee645c783a1d67", userId);
            Object stuResult = result.getResult();
            Map stuMap = (Map)stuResult;
            if ((stuMap != null) && (!"".equals(stuMap)))
            {
                String s = JSON.toJSONString(stuMap);
                VeBaseStudent veBaseStudent = (VeBaseStudent)JSON.parseObject(s, VeBaseStudent.class);
                if ((veBaseStudent != null) && (!"".equals(veBaseStudent)))
                {
                    VeApply veApply = this.veChangeMapper.getVeApplyByStuId(veBaseStudent.getId());
                    if ((veApply != null) && (!"".equals(veApply)))
                    {
                        if (veApply.getType() == 2)
                        {
                            boolean b = false;
                            return Result.OK(Boolean.valueOf(b));
                        }
                        boolean b = true;
                        return Result.OK(Boolean.valueOf(b));
                    }
                }
            }
        }
        return Result.OK();
    }

    public VeChange getChangeByUserIdAndStatus(String userId, Integer status)
    {
        return this.veChangeMapper.getChangeByUserIdAndStatus(userId, status);
    }
}
